﻿using NHibernate;
using NHibernate.Criterion;
using NovelDB;
using NovelDB.Entity;

namespace NovelReader.Manager
{
    public class DBNovelManager : INovelManage
    {
        private ISession Session { get; set; }

        public DBNovelManager()
        {
            NHibernateHelper helper = new NHibernateHelper();
            Session = helper.GetSession();
        }

        /// <summary>
        /// 检查小说
        /// </summary>
        /// <param name="novel"></param>
        public void CheckNovel(NovelReader.Novel novel)
        {
            var hn = Session.CreateCriteria<HNovel>()
                        .Add(Restrictions.Eq("Name", novel.NovelName)).UniqueResult();
            if (hn == null)
            {
                hn = new HNovel { Name = novel.NovelName, SiteName = "", Description = novel.NovelDescription };
                Session.Save(hn);
                Session.Flush();
            }

            foreach (var chap in novel)
            {
                var ch = Session.CreateCriteria<HNovelChapter>()
                    .Add(Restrictions.Eq("Id", "")).UniqueResult();
            }
        }

        public void DownLoadLinks(NovelReader.Novel novel)
        {

        }

    }
}
